package addBinary;

public class Solution {
    // 二进制加法运算
    public String addBinary(String a, String b) {
        StringBuilder sb = new StringBuilder();
        int i = a.length()-1;
        int j = b.length()-1;
        int t = 0; //表示进位
        while(i>=0||j>=0||t>0){
            int sum = t;
            if(i>=0){
                sum+=a.charAt(i)-'0';
            }
            if(j>=0){
                sum+=b.charAt(j)-'0';
            }
            sb.append(sum%2);
            t = sum/2;
        }
        return sb.reverse().toString();
    }
}
